package com.acme.bankapp.domain.account;

import com.acme.bankapp.exceptions.*;

public class CheckingAccount extends AbstractAccount {
    private double overdraft;

    public double getOverdraft() {
        return overdraft;
    }

    // define constructor public CheckingAccount
    public CheckingAccount(final int id, final double amount, final double overdraft) throws IllegalArgumentException {
        super(id, amount);
        setType("CheckingAccount");
        if (overdraft < 0) {
            throw new IllegalArgumentException("CheckingAccount: Overdraft can not be negative");
        }
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(final double amount) throws OverDraftLimitExceededException {
        if(getBalance() + overdraft >= amount){
            setBalance(getBalance() - amount);
        }
        else {
            throw new OverDraftLimitExceededException(this);
        }
    }

    @Override
    public double maximumAmountToWithdraw() {
        return getBalance() + overdraft;
    }


}
